<?php

/*

Forums: View Category (view_cat.php)

*/

$interactive = 1;
$rank_check = 3;
$page_title = "Forums - View Category";
include "header.inc.php";

$getCat = fetch("SELECT * FROM forum_cats2 WHERE id = '$id' AND game = '$game'");

if (!$order)
{
	$orderBY = " ORDER BY last_post_at DESC";
	$queryStuff = " AND category = '$id'";
	if (!$getCat[id]) { die("This category does not exsist.$closeHTML"); }
}
if ($order == "last25")
{
	$orderBY = " ORDER BY last_post_at DESC";
}
if ($order == "newest25")
{
	$orderBY = " ORDER BY id DESC";
}
if ($order == "yourTopics")
{
	$orderBY = " ORDER BY last_post_at DESC";
	$queryStuff = " AND author = '$userid'";
}

$topics = mysql_query("SELECT * FROM forum_subjects2 WHERE game = '$game'$queryStuff$orderBY LIMIT 25");

while ($array = mysql_fetch_array($topics))
{
	if ($rank >= 4) { $delete = " <a href='forum_delete.pro.php?game=$game&topic=$array[id]&order=$order&goto=$id' onClick=\"if ( !confirm ('Are you sure you want to delete this post?') ) { return false; }\"><font size=-1>(Delete!)</font></a>"; }
	$cellcolor = alternate($cellcolor,"$reallyLight","#FFFFFF");
	$get_author = fetch("SELECT username,display_name,premium,display_prem FROM members2 WHERE id = '$array[author]' AND game = '$game'");
	$get_responder = fetch("SELECT username,display_name,premium,display_prem FROM members2 WHERE id = '$array[last_post_by]' AND game = '$game'");
	$lastpost_string = date("M j @ g:i",$array[last_post_at]);

	if (($get_author[premium] == 1) AND ($get_author[display_prem]))
	{
		$get_author[display_name] = $get_author[display_prem];
	}
	if (($get_responder[premium] == 1) AND ($get_responder[display_prem]))
	{
		$get_responder[display_name] = $get_responder[display_prem];
	}

	$numReplies2 = fetch("SELECT count(id) AS id FROM forum_replies2 WHERE game = '$game' AND thread = '$array[id]'");

	if ($numReplies2[id] < 10) { $numReplies = "$numReplies2[id] Replies"; }
	if ($numReplies2[id] >= 10) { $numReplies = "<font color=#CC0099><b>$numReplies2[id] Replies</b></font>"; }
	if ($numReplies2[id] > 25) { $numReplies = "<font color=#009900><b>$numReplies2[id] Replies</b></font>"; }
	if ($numReplies2[id] > 25) { $numReplies = "<font color=#FF0000><b>$numReplies2[id] Replies</b></font>"; }

	$topicID = $array[id];

	if ($numReplies2[id] > 25) { $pages[$topicID] = ceil($numReplies2[id] / 25); }
	if ($pages[$topicID] > 1)
	{
		for ($p = 1; $p <= $pages[$topicID]; $p++)
		{
			if ($p == 1) { $list_pages[$topicID] = "<br><font size=-1>Pages ["; }
			if (($p == 4) AND ($p != "$pages[$topicID]")) { $p = $pages[$topicID] - 1; $list_pages[$topicID] .= "..."; }
			if ($p < $pages[$topicID]) { $list_pages[$topicID] .= "<a href=$base_url/view_topic.php?game=$game&id=$array[id]&page=$p>$p</a>, "; }
			if ($p == $pages[$topicID]) { $list_pages[$topicID] .= "<a href=$base_url/view_topic.php?game=$game&id=$array[id]&page=$p>$p</a>]</font>"; }
		}
	}

	$array[subject] = smilies($array[subject]);

	$topic_list .= "
	<tr bgcolor=$cellcolor onmouseover=\"this.style.background='$middleBG';\" onmouseout=\"this.style.background='$cellcolor';\" width=100%>

<td><p><a href=$base_url/view_topic.php?game=$game&id=$array[id]>$array[subject]</a>$delete$list_pages[$topicID]</p></td>

<td width=115><p align=center><a href=$base_url/user_profile.php?game=$game&user=$get_author[username]>$get_author[display_name]</a></p></td>

<td width=100><p align=center>$numReplies</p></td>

<td width=115><p align=center><font size=-1>Last post by:<br><a href=user_profile.php?game=$game&user=$get_responder[username]>$get_responder[display_name]</a> at:<Br>$lastpost_string</font></p></td></tr>";

}

echo $openHTML;

$findPage = fetch("SELECT * FROM game_pages WHERE page_title = '$page_title' AND game = '$game'");
if (!$findPage[id])
{
	print "<p><b>Welcome to the forums. Failure to obey the rules may result in suspension of your account. <font color=red>Remember to Keep it clean, anything over PG will bedeleted.</font></b></p>

";

}
else
{
	include "showpage.inc.php";
	$findPage[page_info] = eregi_replace("\(category\)", "$getCat[cat_name]", $findPage[page_info]);
	$findPage[page_info] = eregi_replace("\(categoryid\)", "$getCat[id]", $findPage[page_info]);
	print "$findPage[page_info]";
}

ECHO <<<END

<center><table><tr>
<td>
<form action=add_topic.php?game=$game&add_to=$id method=post>
<input type=submit value="Add Topic">
</form>
</td>
<td>
<form action=view.php?game=$game&order=last25 method=post>
<input type=submit value="Last 25 Posts">
</form>
</td>
<td>
<form action=view.php?game=$game&order=newest25 method=post>
<input type=submit value="Newest 25 Posts">
</form>
</td>
<td>
<form action=view.php?game=$game&order=yourTopics method=post>
<input type=submit value="Your Topics">
</form>
</td>
<td>
<form action=search_forums.php?game=$game method=post>
<input type=submit value="Search Forums">
</form>
</td>

</tr></table>

<CENTER><BR> <TABLE BGCOLOR="$tableOutline" CELLSPACING=1 CELLPADDING=0 WIDTH=95%>

<tr bgcolor=$topAndBottomBG width=100%><td><p><font color=$topAndBottomText><b>Topic</b></font></p></td><td width=115><p align=center><font color=$topAndBottomText><b>Author</b></font></p></td><td width=100><p align=center><font color=$topAndBottomText><b>Replies</b></font></p></td><td width=115><p align=center><font color=$topAndBottomText><b>Last Action</b></font></p></td></tr>$topic_list</table><br>

END;

echo $closeHTML;

?>